package com.mylk0606.hello.controller;

import cn.hutool.log.StaticLog;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

/**
 * hello控制器
 */
@Controller
@RequestMapping("/hello")
public class HelloController {

    @Value("${hello.prefix}")
    private String helloPrefix;

    @Value("${hello.version}")
    private String helloVersion;

//    @RequestMapping("/")
//    @ResponseBody
//    public Object hello(@RequestParam("name") String name) {
//        Map<String, Object> outMap = new HashMap<>();
//        String hostAddress = null;
//        String hostName = null;
//        try {
//            InetAddress addr = InetAddress.getLocalHost();
//            hostAddress = addr.getHostAddress();
//            hostName = addr.getHostName();
//            StaticLog.info("IP地址：" + hostAddress + "，主机名：" + hostName);
//        } catch (UnknownHostException e) {
//            e.printStackTrace();
//        }
//        String msg = helloVersion + "=>" + hostAddress + "=>" + hostName + "=>hello " + helloPrefix + "-" + name;
//        StaticLog.info(msg);
//        outMap.put("msg", msg);
//        return outMap;
//    }

    @RequestMapping("/{name}")
    @ResponseBody
    public Object hello2(@PathVariable("name") String name) {
        Map<String, Object> outMap = new HashMap<>();
        String hostAddress = null;
        String hostName = null;
        try {
            InetAddress addr = InetAddress.getLocalHost();
            hostAddress = addr.getHostAddress();
            hostName = addr.getHostName();
            StaticLog.info("IP地址：" + hostAddress + "，主机名：" + hostName);
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        String msg = "test构建镜像:update27=>" + helloVersion + "=>" + hostAddress + "=>" + hostName + "=>hello " + helloPrefix + "-" + name;
        StaticLog.info(msg);
        outMap.put("msg", msg);
        return outMap;
    }

}
